class TrieNode {
    val=''
    children=[]
    conut = 0
    constructor(val){
        this.val = val
        // 假设全部都是 a-z，一共 26 个字符
        // 当然也可以初始化为 []，后面使用 push 时检查
        this.children = new Array(26)
    }
}
const root = new TrieNode('root')
// 插入
function insert(val){
    let current = root
    for (let i = 0; i < val.length; i++) {
        const index = val.codePointAt(i) - 'a'.codePointAt()
        if(current.children[index] === undefined){
            current.children[index] = new TrieNode(val[i])
        }
        current = current.children[index]
    }
    current.conut ++ // 标记节点
}
// 查询
function query(val){
    let current = root
    for (let i = 0; i < val.length; i++) {
        const index = val.codePointAt(i) - 'a'.codePointAt()
        const searchNode = current.children[index]
        if(!searchNode){return null}
        current = searchNode
    }
    return current.conut
}
const arrs = ['code','cook','cool','cool','cool','format','food','from']
for (let i = 0; i < arrs.length; i++) {
    insert(arrs[i])
}
console.log(root)
console.log(query('code'))
